﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    [ValueConversion(typeof(TimeSpan), typeof(bool))]
    public class TimeSpanToStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return "0;0;0";
           return ((TimeSpan)value).ToString(Tools.TimeSpan_hhmmssfff);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return new TimeSpan(0);
            if (TimeSpan.TryParse(value.ToString(), out TimeSpan result))
                return result;
            return new TimeSpan(0);
        }
    }
}
